package com.woniu.customer.controller;

import com.woniu.customer.pojo.*;
import com.woniu.customer.service.*;
import com.woniu.pojo.PageParam;
import com.woniu.until.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CustomerController {

    @Autowired
    private CustomerAdditionService customerAdditionService;

    @Autowired
    private ReconsigneesUnitService reconsigneesUnitService;

    @Autowired
    private OrderbillingsUnitService orderbillingsUnitService;

    @Autowired
    private TransportUpgradesService transportUpgradesService;

    @Autowired
    private RequestSpecialService requestSpecialService;

    /**
     * 数据库新增客户基本资料
     * @param customer
     * @return
     */
    @PostMapping("/addCustomer")
    public String addCustomer(@RequestBody CustomerAddition customer){
        String msg =customerAdditionService.addCustomer(customer);
        return msg;
    }

    /**
     * redis新增客户基本资料
     * @param customer
     * @return
     */
    @PostMapping("/addCustomerRedis")
    public ResponseData<?> addCustomerRedis(@RequestBody CustomerAddition customer){
        return customerAdditionService.addCustomerRedis(customer);
    }

    /**
     * 数据库新增收货/收票单位
     */
    @PostMapping("/addReConsignees")
    public String addReConsignees(@RequestBody ReconsigneesUnit reconsignees){
        String msg = reconsigneesUnitService.addReConsignees(reconsignees);
        return msg;
    }

    /**
     * redis新增收货/收票单位
     */
    @PostMapping("/addReConsigneesRedis")
    public ResponseData<?> addReConsigneesRedis(@RequestBody ReconsigneesUnit reconsignees){
        return reconsigneesUnitService.addReConsigneesRedis(reconsignees);
    }


    /**
     * 数据库新增开票/订货单位
     */
    @PostMapping("/addOrderBillings")
    public String addOrderBillings(@RequestBody OrderbillingsUnit orderbillings){
        String msg =orderbillingsUnitService.addOrderBillings(orderbillings);
        return msg;
    }


    /**
     * redis新增开票/订货单位
     */
    @PostMapping("/addOrderBillingsRedis")
    public ResponseData<?> addOrderBillingsRedis(@RequestBody OrderbillingsUnit orderbillings){
        return orderbillingsUnitService.addOrderBillingsRedis(orderbillings);
    }

    /**
     * 客户资料修改
     */
    @PostMapping("/updateCustomer")
    public boolean updateCustomer(@RequestBody CustomerAddition customer){
        return customerAdditionService.updateCustomer(customer);
    }

    /**
     * 运输方式新增升级
     */
    @PostMapping("/addTransport")
    public String addTransport(@RequestBody TransportUpgrades transportUpgrades){
        String msg = transportUpgradesService.addTransport(transportUpgrades);
        return msg;
    }

    /**
     * 特殊发货申请
     */
    @PostMapping("/addSpecial")
    public String addSpecial(@RequestBody RequestSpecial requestSpecial){
        String msg = requestSpecialService.addSpecial(requestSpecial);
        return msg;
    }

    /**
     * 通过客户ID查询订单相关信息
     * @param customerId
     * @return
     */
    @PostMapping("/queryByCustomerId")
    public ReconsigneesUnit queryByCustomerId(Long customerId){
       return reconsigneesUnitService.queryByCustomerId(customerId);
    }

    /**
     * 页面展示分页
     * @param pageParam
     * @return
     */
    @PostMapping("/queryAllBasic")
    public ResponseData<?> queryAllBasic(@RequestBody PageParam<CustomerAddition> pageParam){
       return customerAdditionService.queryAllBasic(pageParam);
    }



}
